package com.weiyuwqj.server.service.picture.impl;

import com.github.pagehelper.PageHelper;
import com.weiyuwqj.server.service.base.BaseServiceImpl;
import com.weiyuwqj.server.mapper.SysPictureMapper;
import com.weiyuwqj.api.service.SysPictureService;
import com.weiyuwqj.api.common.PageList;
import com.weiyuwqj.api.common.Paginator;
import com.weiyuwqj.api.model.BasItem;
import com.weiyuwqj.api.model.SysArticle;
import com.weiyuwqj.api.model.SysPicture;
import com.weiyuwqj.api.util.IpUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2015/12/7.
 */
@Service("pictureService")
public class SysPictureServiceImpl extends BaseServiceImpl<SysPicture> implements SysPictureService {
    @Autowired
    SysPictureMapper sysPictureMapper;

    @Override
    public PageList getList(Paginator p, Map<String, Object> param) {
        PageHelper.startPage(p.getPageNum(), p.getPageSize());
        return new PageList(sysPictureMapper.getList(param));
    }

    @Override
    public SysPicture getSingle(Integer id) {
        return sysPictureMapper.getSingle(id);
    }


    //获取图片地址
    @Override
    public List<SysPicture> getPictureByItemId(Map map) {
        return sysPictureMapper.getPictureByItemId(map);
    }

    @Override
    public void deleteByItemId(Map map) {
        sysPictureMapper.deleteByItemId(map);
    }

    /**
     * 根据type获取图片
     * @param type 图片类型
     * @return 图片列表
     */
    @Override
    public List<SysPicture> getMainPicture(Integer type) {
        return sysPictureMapper.getMainPicture(type);
    }

    @Override
    public List<SysPicture> getPartnerPicture() {
        return sysPictureMapper.getPartnerPicture();
    }

    /**
     * 查询项目图片
     * @param p
     * @param param
     * @return
     */
    @Override
    public PageList getListByItemPicture(Paginator p, Map<String, Object> param) {
        PageHelper.startPage(p.getPageNum(), p.getPageSize());
        return new PageList(sysPictureMapper.getListByItemPicture(param));
    }


    @Override
    public void addArticlePic(String pics,SysArticle article) {


            SysPicture pic = new SysPicture();
            pic.setAddip(IpUtils.get());
            pic.setAddtime(new Date());
            pic.setItemId(article.getId());
            pic.setPictureName(article.getId()+"");
            pic.setPictureUrl(pics);
            pic.setPicturePath(pics);
            pic.setSequence(1);
            pic.setPictureType(5);
            sysPictureMapper.addArticlePic(pic);
        }
    @Override
    public void deleteById(Integer id){
        sysPictureMapper.deleteById(id);
    }

    //App活动中心页面
    @Override
    public PageList getListByActivity(Paginator p) {
        PageHelper.startPage(p.getPageNum(), p.getPageSize());
        return new PageList(sysPictureMapper.getListByActivity());
    }

    //根据id修改项目图片类型
    @Override
    public Integer modifyItemPictureTypeById(@Param("itemPictureType") Integer itemPictureType, @Param("id") Integer id) {
        return sysPictureMapper.modifyItemPictureTypeById(itemPictureType,id);
    }

    @Override
    public SysPicture getScreenPicture() {
        return sysPictureMapper.getScreenPicture();
    }

    /**
     * 根据不同类型获取图片
     *
     * @param itemId 标ID
     * @param type   项目图片类型  1个人资料 2车辆图片 3相关手续 4风控垫付 5 技术保障
     * @return 标信息
     */
    @Override
    public List<SysPicture> getListByType(Integer itemId, Integer type) {
        return sysPictureMapper.getListByType(itemId, type);
    }
}

